import java.util.Arrays;

/**
 * @Author 12629
 * @Description：
 */
public class Test6666 {

    public static void main(String[] args) {
        int[][] array = new int[2][];
        array[0] = new int[]{1,2};
        array[1] = new int[]{1,2,3};

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] +" ");
            }
            System.out.println();
        }
    }

    public static void main13(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};
     /*   System.out.println(array.length);

        System.out.println(array[0].length);
        System.out.println(array[1].length);*/

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] +" ");
            }
            System.out.println();
        }
        System.out.println("====");
        System.out.println(Arrays.deepToString(array));
        System.out.println("====");

        for(int[] tmp : array) {
            for(int x : tmp) {
                System.out.print(x+" ");
            }
            System.out.println();
        }

    }

    public static void main12(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};
        System.out.println(array[0][1]);

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(array[i][j] +" ");
            }
            System.out.println();
        }

    }

    public static void main11(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};
        int[][] array2 = new int[][]{{1,2,3},{4,5,6}};
        int[][] array3 = new int[2][3];


        //行 不能省略
        //int[][] array4 = new int[][3];

        //不规则二维数组
        int[][] array5 = new int[2][];


    }

    public static void main10(String[] args) {
        int[] array1 = {2,4,6,3};

        /*int[] copy = new int[array1.length];

        for (int i = 0; i < array1.length; i++) {
            copy[i] = array1[i];
        }
        System.out.println(Arrays.toString(copy));*/


        System.out.println("==============");
        int[] copy1 = Arrays.copyOf(array1,array1.length*2);
        System.out.println(Arrays.toString(copy1));/**/
        System.out.println("==============");
        int[] copy2 = Arrays.copyOfRange(array1,0,3);
        System.out.println(Arrays.toString(copy2));
        System.out.println("====1111==========");


        int[] copy = new int[array1.length];
        System.arraycopy(array1,0,copy,0,array1.length);
        System.out.println(Arrays.toString(copy));



    }

    public static void main9(String[] args) {
        int[] array1 = {2,4,6,3};
        int[] array2 = {2,4,6,3,10};

        System.out.println(Arrays.equals(array1, array2));

        int[] array = new int[10];
        Arrays.fill(array,0,3,9);//[0,3)
        System.out.println(Arrays.toString(array));


        /*System.out.println(binarySearch(array, 2));
        System.out.println(binarySearch(array, 6));
        System.out.println(binarySearch(array, 101));

        System.out.println(Arrays.binarySearch(array, 101));*/


        /*int[] ret = findNum(array,7);
        System.out.println(Arrays.toString(ret));*/
    }


    /**
     * https://leetcode.cn/problems/three-consecutive-odds/submissions/
     * @param arr
     * @return
     */
    public boolean threeConsecutiveOdds(int[] arr) {
        int count = 0;//计数器

        for(int i = 0;i < arr.length;i++) {
            if(arr[i] % 2 != 0) {
                count++;
                if(count == 3) {
                    return true;
                }
            }else {
                count = 0;//一定得置为0  才能证明是连续的
            }
        }

        return false;
    }

    //摩尔投票法
    public static int func5(int[] array) {
        Arrays.sort(array);
        return array[array.length/2];
    }

    public static int func4(int[] array) {
        int ret  = 0;
        for (int i = 0; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }

    /**
     * https://leetcode.cn/problems/two-sum/submissions/
     * @param array
     * @param target
     * @return
     */
    public static int[] findNum(int[] array,int target) {
        int[] ret = {-1,-1};
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i] + array[j] == target) {
                    //return new int[]{i,j};
                    ret[0] = i;
                    ret[1] = j;
                }
            }
        }
        return ret;
    }

    public static int binarySearch(int[] array,int key) {
        int i = 0;
        int j = array.length-1;
        while (i <= j) {
            int mid = (i+j) / 2;
            if(array[mid] < key) {
                i = mid+1;
            }else if(array[mid] == key) {
                return mid;
            }else {
                j = mid-1;
            }
        }
        return -1;//没有找到
    }




    public static void main2(String[] args) {
       /* int[] array = {1,2,3};
        System.out.println(Arrays.toString(array));
        int[] ret = func2(array);
        System.out.println(Arrays.toString(ret));*/
        int[] array = {2,4,6,8,1};
        func3(array);
        System.out.println(Arrays.toString(array));
    }

    public static void func3(int[] array) {
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            while (i < j && array[i] % 2 != 0) {
                i++;
            }
            //i下标走完就是一个偶数
            while (i < j && array[j] % 2 == 0) {
                j--;
            }
            //j下标走完就是一个奇数      2 4  6 8

            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    public static int[] func2(int[] array) {
        int[] ret = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            ret[i] = 2 * array[i];
        }
        return ret;
    }

    public static void func1(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = 2 * array[i];
        }
    }


    public static void move(char pos1,char pos2) {
        System.out.print(pos1+" => " + pos2+" ");
    }

    /**
     *
     * @param n 盘子数目
     * @param pos1 起始位置
     * @param pos2 中转位置
     * @param pos3 目的地位置
     */
    public static void hanio(int n,char pos1,char pos2,char pos3) {
        if(n == 1) {
            move(pos1,pos3);
            return;
        }
        hanio(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanio(n-1,pos2,pos1,pos3);
    }

    public static void main1(String[] args) {
        hanio(1,'A','B','C');
        System.out.println();
        hanio(2,'A','B','C');
        System.out.println();
        hanio(3,'A','B','C');
        System.out.println();

    }
}
